package com.ncu.spring.aop.proxy;

import com.ncu.spring.ApplicationContext;

/**
 * 用于构造方法注入时的延迟注入
 * 有可能注入的是个多例 bean，所以每次都从容器中获取，不能缓存起来
 */
public class LazyInjectTargetSource implements TargetSource {
    //Spring容器
    private final ApplicationContext applicationContext;
    //BeanName : 这个BeanName 应该是被注入对象的BeanName
    private final String beanName;

    public LazyInjectTargetSource(ApplicationContext applicationContext, String beanName) {
        this.applicationContext = applicationContext;
        this.beanName = beanName;
    }

    @Override //从容器 中获取Bean
    public Object getTarget() throws Exception {
        return applicationContext.getBean(beanName);
    }
}
